package batframework.db;

import java.util.Map;

import batframework.code.util.StringUtils;


public class Model
{
	private String id = "id";
	
	private String tableName = getDefaultTableName();
	
	public Db db;
	
	protected final void init(String id,String tableName)
	{
		this.id = id;
		this.tableName = tableName;
	}
	
	public Model set(String name,Object value)
	{
		return this;
	}
	

	public Model query(String sql,Object...params)
	{
		return this;
	}
	
	public Model query(String sql,Map<String, Object> param)
	{
		return this;
	}

	public Model()
	{
		super();
	}

	public Model(String primaryKey)
	{
		this.setPrimaryKey(primaryKey);
	}

	public String getPrimaryKey()
	{
		return id;
	}

	public void setPrimaryKey(String pk)
	{
		this.id = pk;
	}

	public String getTableName()
	{
		return tableName;
	}

	public void setTableName(String tableName)
	{
		this.tableName = tableName;
	} 
	
	private String getDefaultTableName()
	{
		String tableName = this.getClass().getSimpleName();
		int index = tableName.indexOf("Model");
		int end = tableName.length();
		if(index !=  -1)
			end = index;
		return StringUtils.firstToLowerCase(tableName.substring(0, end));
	}
}
